package lium.lbs.lbsim.adapter

import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import lium.lbs.lbsim.R
import lium.lbs.lbsim.activity.SystemMessageActivity
import lium.lbs.lbsim.bean.ApplyList

class SystemMessageAdapter : BaseQuickAdapter<ApplyList, BaseViewHolder>(R.layout.conv_list_adpter_view_sm) {
    override fun convert(helper: BaseViewHolder?, item: ApplyList?) {


        helper?.getView<TextView>(R.id.all_agree)
            ?.setOnClickListener(View.OnClickListener {
                when (item?.role) {
                    //我申请入群{gRBean.getGroupName()}
                    "1" -> {
                        (mContext as SystemMessageActivity).getAgreetQun(item?.id, "2", item.groupName.toString())
                    }
                    //{getNickName}邀请我加入群{getGroupName}
                    "2" -> {
                        (mContext as SystemMessageActivity).getAgreetQun(item?.id, "2", item.groupName.toString())
                    }

                    //我邀请{getNickName}加入群{getGroupName}
                    "3" -> {
                    }

                    //好友{getNickName}申请加我
                    "4" -> {
                        (mContext as SystemMessageActivity).getAgreetOrRefuse(item?.id, "2")
                    }

                }
            })

        helper?.getView<TextView>(R.id.tv_refuse)
            ?.setOnClickListener(View.OnClickListener {
                when (item?.role) {
                    //我申请入群{gRBean.getGroupName()}
                    "1" -> {
                        (mContext as SystemMessageActivity).getAgreetQun(item?.id, "3", item.groupName.toString())
                    }
                    //{getNickName}邀请我加入群{getGroupName}
                    "2" -> {
                        (mContext as SystemMessageActivity).getAgreetQun(item?.id, "3", item.groupName.toString())
                    }

                    //我邀请{getNickName}加入群{getGroupName}
                    "3" -> {
                    }

                    //好友{getNickName}申请加我
                    "4" -> {
                        (mContext as SystemMessageActivity).getAgreetOrRefuse(item?.id, "3")
                    }

                }
            })

        helper?.getView<TextView>(R.id.tv_time)?.text = item?.addTime

        when (item?.role) {
            //我申请入群{gRBean.getGroupName()}
            "1" -> {
                helper?.getView<TextView>(R.id.tv_sm)?.text = item?.mNickName +"申请加入" + item?.groupName+"群"
            }
            //{getNickName}邀请我加入群{getGroupName}
            "2" -> {
                helper?.getView<TextView>(R.id.tv_sm)?.text = item?.mNickName + "邀请我加入群" + item?.groupName
            }

            //我邀请{getNickName}加入群{getGroupName}
            "3" -> {
                helper?.getView<TextView>(R.id.tv_sm)?.text = "我邀请" + item?.mNickName + "加入群" + item?.groupName
            }

            //好友{getNickName}申请加我
            "4" -> {
                helper?.getView<TextView>(R.id.tv_sm)?.text =  item?.mNickName + "申请加我为好友"
            }

        }
        ////1 申请中 2申请成功 //已拒绝
        when (item?.status) {
            "1" -> {
                helper?.getView<TextView>(R.id.tv_time)?.text = ""
                helper?.getView<LinearLayout>(R.id.tv_ar)!!.visibility = View.VISIBLE
            }
            "2" -> {
                helper?.getView<TextView>(R.id.tv_time)?.text = "已同意"
                helper?.getView<LinearLayout>(R.id.tv_ar)!!.visibility = View.GONE
            }

            "3" -> {
                helper?.getView<TextView>(R.id.tv_time)?.text = "已拒绝"
                helper?.getView<LinearLayout>(R.id.tv_ar)!!.visibility = View.GONE
            }
        }
    }
}


